package com.example.ndkjnidemo.home.reference;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.LogUtils;
import com.example.ndkjnidemo.databinding.ActivityRefBinding;

/**
 *
 */
public class RefActivity extends AppCompatActivity {

    private static final String TAG = "RefActivity";
    private ActivityRefBinding binding;
    private JNIRef jniRef = new JNIRef();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityRefBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        //===
        onJniRef();
    }

    public void onJniRef() {
        String s = jniRef.jnilocalRef();
        LogUtils.i(TAG, "jnilocalRef=" + s);

        String ret1 = jniRef.jniGlobalRef();
        LogUtils.i(TAG, "jniGlobalRef=" + ret1);
        String ret2 = jniRef.jniGlobalRef();
        LogUtils.i(TAG, "jniGlobalRef=" + ret2);
        jniRef.delGlobalRef();

        String ret3 = jniRef.jniWeakGlobalRef();
        LogUtils.i(TAG, "jniWeakGlobalRef=" + ret3);
        String ret4 = jniRef.jniWeakGlobalRef();
        LogUtils.i(TAG, "jniWeakGlobalRef=" + ret4);
        jniRef.delWeakGlobalRef();

        jniRef.localRefOverflow();
        jniRef.refSame();

        String ret5 = jniRef.refCache();
        LogUtils.i(TAG, "refCache=" + ret5);
        String ret6 = jniRef.refCache();
        LogUtils.i(TAG, "refCache=" + ret6);
        jniRef.delRefCache();
    }
}